package com.hm.service.service.user;

import com.hm.service.mapper.user.UserMapper;
import com.hm.service.pojo.db.UserBean;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.HashMap;


@Service
public class UserService implements IUserService {

    @Qualifier("MainSqlSessionFactory")
    private final SqlSessionFactory sqlSessionFactory;

    public UserService(SqlSessionFactory sqlSessionFactory) {
        this.sqlSessionFactory = sqlSessionFactory;
    }

    @Override
    public UserBean getUserForName(String userName) {
        //验证用户合法性
        try (SqlSession session = sqlSessionFactory.openSession(true)) {
            UserMapper mapper = session.getMapper(UserMapper.class);
            HashMap<String, String> params = new HashMap<>();
            params.put("userName", userName);
            return mapper.getUser(params);
        }
    }
}
